<template>
    <div>
        <h1>
           <el-button type="primary" @click="download()" >主要按钮</el-button>
        </h1>
        <el-table :data="tableData" stripe border style="width: 100%">
            <el-table-column prop="_time" label="更新时间" width="360"  align="center"></el-table-column>
            <el-table-column prop="name" label="文件名" width="360"  align="center"></el-table-column>
            <el-table-column prop="size" label="文件大小"  align="center"></el-table-column>
            <el-table-column  label="操作" align="center">
                <template slot-scope="scope">
                 <el-button size="mini" @click="preview(scope.$index, scope.row)">预览</el-button>
                 <el-button size="mini" type="primary" @click="download(scope.$index, scope.row)">下载</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template> 
<script>
import axios from 'axios';
import {searchFile,downloadFile} from '../../api/api';
import moment from 'moment';
export default {
     data() {
      return {
        tableData: []
      }
    },
    created(){
        searchFile().then(res=>{
            res.forEach(item=>{
                item._time = moment(item.time).format("YYYY-MM-DD HH:mm:ss");
            })
          this.tableData = res;
        });
    },
    methods:{
        download(index,row){
             console.log(index,row);
            downloadFile({filename:row.name,database:'file'}).then(res=>{
                var {code,path} = res;
               if(code == 1){
                   window.location.href = path;
               }else{
                   console.log(code);
               }
            });
        },
        preview(index,row){
            console.log(index,row);
        }
    }
}
</script>
<style lang="scss" scoped>

</style>

